﻿#ifndef RECORDTABLEMODEL_H
#define RECORDTABLEMODEL_H

#include <QAbstractTableModel>
#include <QJsonObject>
#include <QJsonArray>
#include <QStringList>

class RecordTableModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    explicit RecordTableModel(QObject *parent = nullptr);
    void setJsonData(const QJsonValue &jsonData);
    void addRecord(const QJsonObject &newRecord);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    void setPageSize(int pageSize);
    void firstPage();
    void prevPage();
    void nextPage();
    void lastPage();
    void goToPage(int page);
    int currentPage() const;
    int totalPages() const;

private:
    QJsonArray m_dataArray;  // 存储 JSON 数据的数组
    QStringList m_headers;   // 列表头
    int m_pageSize = 10;     // 每页显示的行数
    int m_currentPage = 0;   // 当前页索引
};

#endif // RECORDTABLEMODEL_H
